#!/usr/bin/python
#!C:\Python27\python.exe
#coding=utf-8
#
import hashlib
import os,sys
import io
import string

def md5_file(name):
    m=hashlib.md5()
#    the_file = open (name,'rb')
    the_file = io.FileIO(name,'r')
    bytes = the_file.read(1024)
    while (bytes != b''):
        m.update(bytes)
        bytes = the_file.read(1024)
    the_file.close()
    
#    m.update(the_file.read())

    print 'the file md5(32) is: ' + m.hexdigest()
    
def hash1_file(name):
    m=hashlib.sha1()
    the_file = open (name,'rb')
    m.update(the_file.read())
#    return m.hexdigest()
    print 'the file sha1(40) is: ' + m.hexdigest()
    
def printUsage():
    print ('''''Usage: [python] pymd5sum.py <filename>''')
    
if __name__ == '__main__':
    if (sys.argv.__len__()==2):
        md5_file(sys.argv[1])
        hash1_file(sys.argv[1])
    if (sys.argv.__len__()==1):
        filename = raw_input("Enter the file path: ")
        if os.path.exists(filename):
            md5_file(filename)
            hash1_file(filename)
        else:
            print ("there is not found file")
    raw_input("enter any key and exit!!")
#    print (sys.argv[0])
#    print (sys.argv[1])
    
#string_md5 = hashlib.md5(files).hexdigest()
#string_sha1 = hashlib.sha1(files).hexdigest()
#string_sha224 = hashlib.sha224(files).hexdigest()
#string_sha256 = hashlib.sha256(files).hexdigest()
#string_sha384 = hashlib.sha384(files).hexdigest()
#string_sha512 = hashlib.sha512(files).hexdigest()

#print 'the file md5(32) is: ' + md5_file(filename)
#print 'the file sha1(40) is: ' + hash1_file(filename)
#print 'the file sha1(40) is: ' + string_sha1
#print 'the file sha224(56) is: ' + string_sha224
#print 'the file sha256(64) is: ' + string_sha256
#print 'the file sha384(86) is: ' + string_sha384
#print 'the file sha512(118) is: ' + string_sha512

